package com.eling.elcms.travel.model;

import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Entity
@Indexed
@Table(name = "fp_approvalinstance")
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class) })
public class ApprovalInstance  extends BaseModel {

	private static final long serialVersionUID = -6982607298878329112L;

	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkApprovalInstance;

	/** 对应审批流程 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkApprovalDefine")
	@In
	private ApprovalDefine approvalDefine;

	/** 审批过程 */
	@OneToMany(mappedBy = "approvalInstance")
	@IndexedEmbedded(depth = 1)
	private Set<ApprovalProcess> approvalProcesses;

	/** 对应ModelPK */
	@Column
	@Field
	private Long modelId;

	/** 当前进行位置 */
	@Column
	@Field
	private Integer position;
 
	/** 审批开始日期 */
	@Column
	@Field
	@Between
	private Date createTime;

	/** 当前流程状态 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private FlowStatus flowStatus;

	@Version
	private Integer version;

	public Long getPkApprovalInstance() {
		return pkApprovalInstance;
	}

	public void setPkApprovalInstance(Long pkApprovalInstance) {
		this.pkApprovalInstance = pkApprovalInstance;
	}

	public ApprovalDefine getApprovalDefine() {
		return approvalDefine;
	}

	public void setApprovalDefine(ApprovalDefine approvalDefine) {
		this.approvalDefine = approvalDefine;
	}


	public Set<ApprovalProcess> getApprovalProcesses() {
		return approvalProcesses;
	}

	public void setApprovalProcesses(Set<ApprovalProcess> approvalProcesses) {
		this.approvalProcesses = approvalProcesses;
	}

	public Long getModelId() {
		return modelId;
	}

	public void setModelId(Long modelId) {
		this.modelId = modelId;
	}

	public Integer getPosition() {
		return position;
	}

	public void setPosition(Integer position) {
		this.position = position;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public FlowStatus getFlowStatus() {
		return flowStatus;
	}

	public void setFlowStatus(FlowStatus flowStatus) {
		this.flowStatus = flowStatus;
	}
	
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}
